﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CFSystem.JXC.BLL
{
    using CFSystem.JXC.IDAL;
    using CFSystem.JXC.Model;

    public class ProductBLL
    {
        // Get an instance of the Product DAL using the DALFactory
        // Making this static will cache the DAL instance after the initial load
        private static readonly IProductDAL dal = DALFactory.DataAccess.CreateProduct();

        public ProductBLL()
        { }
        /// <summary>
        /// Method to get all products
        /// </summary>										
        /// <returns>Generic List of ProductInfo</returns>	   		
        public IList<ProductInfo> GetAllProducts()
        {
            return dal.GetAllProducts();
        }
        
         /// <summary>
         /// insert a new product into db.
         /// </summary>
         /// <param name="product">Product object to be added</param>
        public void Insert(ProductInfo product)
        {
            //check name
            
            //insert
            dal.AddProduct(product);
        }

        /// <summary>
        /// Delete a product
        /// </summary>
        /// <param name="productID">Product ID</param>
        public void Delete(string productID)
        {
            dal.DeleteProduct(productID);
        }

        /// <summary>
        /// Update an existing product object
        /// </summary>
        /// <param name="product">Product object to be updated</param>
        public void Update(ProductInfo product)
        {
            dal.UpdateProduct(product);
        }

        /// <summary>
        /// Get the specified product by id
        /// </summary>
        /// <param name="productID">Product ID</param>
        /// <returns>The product object matched the ID</returns>
        public ProductInfo GetProductByID(string productID)
        {
            IList<ProductInfo> products = dal.SearchProduct(productID);
            if (products.Count >= 1)
            {
                return products[0];
            }
            else
            {
                return null;
            }
        }

        public IList<ProductInfo> SearchProducts(string strSearch)
        {
            return dal.SearchProduct(strSearch);
        }
    }
}
